<?php


class Category_model extends Model
{
	function __construct()
	{
		parent::__construct();
		$this->category_list = $this->getCategoryList();
	}
	
	function getCategoryList($select = '*',$order = ' order by Top desc,CategoryID asc',$page = 0,$num = 0)
	{
		
		$this->setLimit($num);
		$this->setPage($page);
		$this->setOrder($order);
		return $this->getDataList('category',$select);;
		
	}
	
	

	//辅助函数
	function getCategoryForSelect($root_id = 0,$currently_id = 0,$pre = '&nbsp;&nbsp;&#8250;&nbsp;',$level = 0)
	{

		if(!empty($this->category_list))
		{
			foreach ($this->category_list as $key => $value)
			{
				if($root_id == $value['ParentID'])
				{
					for($i=0;$i<=$level;$i++)
					{
						$currently_pre .= $pre;
					}

					if($currently_id == $value['CategoryID'])
					{
						$this->category_select_list .= '<option value="' . $value['CategoryID'] . '" selected="selected">' . $currently_pre . $value['CategoryName'] . '</option>' . "\n";
					}
					else
					{
						$this->category_select_list .= '<option value="' . $value['CategoryID'] . '">' . $currently_pre . $value['CategoryName'] . '</option>' . "\n";
					}

					unset($currently_pre);
					$this->getCategoryForSelect($value['CategoryID'],$currently_id,$pre,$level + 1);

				}
			}
		}

		return $this->category_select_list;
	}
}
?>